package com.yoga.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoga.model.Member;
import com.yoga.model.search.MemberSearchBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author yan
 * @date 2025/8/8
 */
@Mapper
public interface MemberMapper extends BaseMapper<Member> {
    //查询全部
    default Page<Member> findAll(Page<Member> page, MemberSearchBean msb){
        LambdaQueryWrapper<Member> qw = Wrappers.lambdaQuery(msb);//条件封装器
        if (msb.getBirthdayFrom()!=null){
            qw.ge(Member::getBirthDate,msb.getBirthdayFrom());
        }
        if (msb.getBirthdayTo()!=null){
            qw.lt(Member::getBirthDate,msb.getBirthdayTo());
        }
        return this.selectPage(page,qw);
    }

    @Select("SELECT COUNT(*) FROM member WHERE membership_type = 'VIP'")
    int countVip();

    @Select("SELECT COUNT(*) FROM member WHERE membership_type != 'VIP'")
    int countRegular();

}
